#include "ResourceManager.h"
#include "AssimpLoader.h"

#include "D3d11Utils.h"
#include "D3DX11tex.h"

ResourceManager ResourceManager::sInstance;

ResourceManager::ResourceManager()
{
	mpMeshLoader = new AssimpLoader();
}

ResourceManager::~ResourceManager()
{
	delete mpMeshLoader;
	mpDeviceManager = NULL;
}

const ResourceManager* ResourceManager::GetInst()
{
	return &sInstance;
}

void ResourceManager::Init(DeviceManager* pDevice)
{
	sInstance.mpDeviceManager = pDevice;
}

Mesh* ResourceManager::GetMesh(const char* pFilePath) const
{
	MeshData* pMeshData = NULL;
	mpMeshLoader->LoadFromFile(pFilePath, &pMeshData);

	Mesh* res = NULL;
	if (pMeshData != NULL)
	{
		res = Mesh::Create(pMeshData, mpDeviceManager);
	}

	return res;
}

ID3D11ShaderResourceView* ResourceManager::CreateShaderResourceViewFromFile(const char* pFilePath) const
{
	ID3D11ShaderResourceView* res = NULL;
	HR (D3DX11CreateShaderResourceViewFromFileA(mpDeviceManager->mpDevice, pFilePath, NULL, NULL, &res, &hr) );

	return res;
}

